import axios from 'axios'

import { AMAP_KEY, AMAP_URL } from '@/constants'

const instance = axios.create({
  baseURL: AMAP_URL
})

instance.interceptors.request.use((config) => {
  config.params = {
    ...config.params,
    key: AMAP_KEY
  }

  return config
})

export function useAMap() {
  const getLocation = async () => {
    const res = await instance.get('/ip')
    return res.data
  }

  return {
    getLocation
  }
}
